#ifndef RA_EVENTLOOP_H
#define RA_EVENTLOOP_H

#define NONE        0
#define READABLE    1
#define WRITEABLE   2

#define RA_FILE_EVENTS 1
#define RA_TIME_EVENTS 2
#define RA_ALL_EVENTS  (RA_FILE_EVENTS | RA_TIME_EVENTS)
#define RA_NOT_WAIT    4

struct raEventLoop;
typedef void (*raFileProc)(struct raEventLoop * eventloop,int fd);

typedef struct raFileEvent{
    int mask;
    raFileProc rFileProc;
    raFileProc wFileProc;
    void *clientData;
}raFileEvent;

typedef struct raFiredEvent{
    int fd;
    int mask;
}raFiredEvent;

typedef struct raEventLoop{
    int maxfd;  
    unsigned long setsize;
    raFileEvent  *events;
    raFiredEvent *fires;
    void *apidata;
    int stop;
    // //计时事件
    // long long timeEventNextId;
    // time_t lastTime;  
    // aeTimeEvent *timeEventHead;    
    
    //其他
    // aeBeforeSleepProc *beforesleep;
    // aeBeforeSleepProc *aftersleep;
}raEventLoop;

raEventLoop * ra_create_eventloop(unsigned long size);
int ra_add_event(raEventLoop *eventloop,int fd,raFileProc proc,int mask);
int ra_del_event(raEventLoop *eventloop,int fd,raFileProc proc,int delmask);
raEventLoop * ra_resize_eventloop(raEventLoop * eventloop,unsigned long size);
void ra_free_eventloop(raEventLoop *eventloop);
int ra_process_events(raEventLoop *eventLoop, int flags);

#endif
